home *** CD-ROM | disk | FTP | other *** search
/ Champak 43 / Vol 43.iso / games / penguin.swf / scripts / __Packages / Class / Control.as < prev    next >
Encoding:
Text File  |  2007-06-26  |  3.5 KB  |  143 lines

  1. class Class.Control extends MovieClip
  2. {
  3.    var distanceMax;
  4.    var _V;
  5.    var line_mc;
  6.    var role;
  7.    var opp;
  8.    var side;
  9.    var onMouseMove;
  10.    var onMouseUp;
  11.    var meter_mc;
  12.    var mouse_mc;
  13.    var startX;
  14.    var startY;
  15.    var distance;
  16.    var angle;
  17.    var Vx;
  18.    var Vy;
  19.    var inDraw = false;
  20.    function Control()
  21.    {
  22.       super();
  23.       this.distanceMax = 200;
  24.       this._V = _root.V;
  25.       this.line_mc = _global.cMC("line_mc",this);
  26.    }
  27.    function init(_role, _opp, _side)
  28.    {
  29.       this.role = _role;
  30.       this.opp = _opp;
  31.       this.side = _side;
  32.       trace("side: " + this.side);
  33.    }
  34.    function activeStart()
  35.    {
  36.       var owner = this;
  37.       _root.drawArea.onPress = function()
  38.       {
  39.          owner.mouseDown();
  40.       };
  41.       this.onMouseMove = this.mouseMove;
  42.       this.onMouseUp = this.mouseUp;
  43.    }
  44.    function activeEnd()
  45.    {
  46.       _root.drawArea.onPress = function()
  47.       {
  48.       };
  49.       this.onMouseMove = null;
  50.       this.onMouseUp = null;
  51.       this.meter_mc._x = -100;
  52.       this.meter_mc._y = -100;
  53.    }
  54.    function useMouseCursor()
  55.    {
  56.       Mouse.hide();
  57.       var owner = this;
  58.       this.mouse_mc.onEnterFrame = function()
  59.       {
  60.          this._x = owner._xmouse;
  61.          trace("this: " + this);
  62.          trace("this._x: " + this._x);
  63.          this._y = owner._ymouse;
  64.       };
  65.    }
  66.    function stopMouseCursor()
  67.    {
  68.       Mouse.show();
  69.       this.mouse_mc.onEnterFrame = null;
  70.       this.mouse_mc._x = -100;
  71.       this.mouse_mc._y = -100;
  72.    }
  73.    function mouseDown()
  74.    {
  75.       this.inDraw = true;
  76.       this.startX = this._xmouse;
  77.       this.startY = this._ymouse;
  78.       this.distance = 10;
  79.       _root.roleNow.setReady();
  80.    }
  81.    function mouseMove()
  82.    {
  83.       if(this.inDraw)
  84.       {
  85.          var _loc4_ = this._xmouse;
  86.          var _loc3_ = this._ymouse;
  87.          this.distance = ExtMath.distance(_loc4_,_loc3_,this.startX,this.startY);
  88.          if(this.distance > this.distanceMax)
  89.          {
  90.             this.distance = this.distanceMax;
  91.          }
  92.          this.angle = ExtMath.angleOfLine(_loc4_,_loc3_,this.startX,this.startY);
  93.          var _loc5_ = this.getPower(this.distance);
  94.          _root.roleNow.setAnimation(_loc5_);
  95.          this.meter_mc._x = _loc4_;
  96.          this.meter_mc._y = _loc3_;
  97.          this.meter_mc.point_mc._rotation = this.angle;
  98.          this.meter_mc.bar.mask_mc._rotation = int(this.distance / this.distanceMax * 180);
  99.          if(this.side == 1)
  100.          {
  101.             this.meter_mc.angle_txt.text = ExtMath.fixAngle(int(- this.angle)) + "┬░";
  102.          }
  103.          else
  104.          {
  105.             this.meter_mc.angle_txt.text = int(this.angle + 180) + "┬░";
  106.          }
  107.          this.meter_mc.power_txt.text = int(this.distance / this.distanceMax * 100) + "%";
  108.          updateAfterEvent();
  109.       }
  110.    }
  111.    function mouseUp()
  112.    {
  113.       if(this.inDraw == false)
  114.       {
  115.          return undefined;
  116.       }
  117.       this.inDraw = false;
  118.       this.startControl();
  119.    }
  120.    function getPower(distance)
  121.    {
  122.       var _loc2_ = distance / this.distanceMax;
  123.       return _loc2_;
  124.    }
  125.    function startControl()
  126.    {
  127.       if(isNaN(this.distance))
  128.       {
  129.          this.distance = 20;
  130.       }
  131.       if(isNaN(this.angle))
  132.       {
  133.          this.angle = 30;
  134.       }
  135.       var _loc3_ = this.distance / this.distanceMax;
  136.       var _loc2_ = this._V * _loc3_;
  137.       this.Vx = _loc2_ * ExtMath.cosD(this.angle);
  138.       this.Vy = _loc2_ * ExtMath.sinD(this.angle);
  139.       this.play();
  140.       this.activeEnd();
  141.    }
  142. }
  143.